200
class Solution {
    int x = 0;
    int y = 0;
    public int numIslands(char[][] grid) {
        x = grid.length;
        y = grid[0].length;
        int count = 0;
        for (int i = 0; i  x; i++) {
            for (int j = 0; j  y; j++) {
                if (grid[i][j] == '1') {
                    fun(grid, i, j);
                    count++;
                }
            }
        }
        return count;
    }

    public void fun(char[][] grid, int i, int j) {
        grid[i][j] = '0';
        i++;
        if (i  x && grid[i][j] == '1') {
            fun(grid, i, j);
        }
        i -= 2;
        if (i = 0 && grid[i][j] == '1') {
            fun(grid, i, j);
        }
        i++;
        j++;
        if (j  y && grid[i][j] == '1') {
            fun(grid, i, j);
        }
        j -= 2;
        if (j = 0 && grid[i][j] == '1') {
            fun(grid, i, j);
        }
    }
}
import java.util.*;


public class Solution {

    public String solve (String s, String t) {
        // write code here
        if (s.charAt(0) == '0' || t.charAt(0) == '0'){
            return "0";
        }
        String ret = "0";
        String[] tmp = new String[t.length()]; 
        for (int i = t.length() - 1; i >= 0; i--){
            tmp[i] = "";
            int j = t.length() - 1;
            while(j - i > 0){
                tmp[i] += '0';
                j--;
            }
            tmp[i] += alongMultiply(s, t.charAt(i));
        }
        for (int i = t.length() - 1; i >= 0; i--){
            ret = Add(tmp[i], ret);
        }

        StringBuffer stringBuffer = new StringBuffer();
        for (int i = ret.length() - 1; i >= 0; i--){
            stringBuffer.append(ret.charAt(i));
        }
        ret = stringBuffer.toString();
        return ret;
    }

    public String Add(String a, String b){
        String str = "";
        int aLen = a.length() - 1;
        int ai = 0;
        int bLen = b.length() - 1;
        int bi = 0;
        int ten = 0;

        while(aLen >= ai && bLen >= bi){
            int tmp = (a.charAt(ai++) - '0') + (b.charAt(bi++) - '0');
            tmp += ten;
            ten = tmp / 10;
            str += tmp % 10;
        }
        while(aLen >= ai){
            int tmp = a.charAt(ai++) - '0';
            tmp += ten;
            ten = tmp / 10;
            str += tmp % 10;
        }
        while(bLen >= bi){
            int tmp = b.charAt(bi++) - '0';
            tmp += ten;
            ten = tmp / 10;
            str += tmp % 10;
        }
        if (ten != 0){
            str += ten;
        }
        return str;
    }

    public String alongMultiply(String s, char t){
        String ret = "";
        if (s.charAt(0) == '0' || t == '0'){
            return "0";
        }
        int tt = t - '0';
        int ten = 0;
        for (int i = s.length() - 1; i >= 0; i--){
            int tmp = s.charAt(i) - '0';
            tmp *= tt;
            tmp += ten;
            ten = tmp / 10;
            ret += tmp % 10;
        }
        if (ten != 0){
            ret += ten;
        }

        return ret;
    }
}